package com.educate.book.model.bo;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.PageRequest;

import com.educate.book.model.po.Item;
import com.educate.common.web.RequestUtils;

import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * BO 处理业务数据
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ItemBO extends Item {
    private String uid;
    private Integer page;
    private Integer size;
    private List<String> sortProps;
    private Boolean sortAsc;
    private String keyword;

    public ItemBO() {
    }

    public ItemBO(Item source) {
        BeanUtils.copyProperties(source, this);
    }

    public <T> T map(Converter<ItemBO, T> converter) {
        return converter.convert(this);
    }

    public PageRequest pageable() {
        return RequestUtils.parsePageRequest(getPage(), getSize(), getSortProps(), getSortAsc());
    }
}
